/** @jsxImportSource @emotion/react */
import * as React from "react";
import {OriginalViewProps } from "../../common/base";
import {
    EntranceSetup, config观测数据, config观测数据2, config设备概况,
} from "./orcBase";
import {createItem, } from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemInstrumentTable} from "../../common/Instrument";
import {ActionMapItemLikeSafeEval} from "../ActionMapItemLikeSafeEval";
import {ItemRecheckEvaluateSplitR} from "../editor";
import {FrontCover} from "../elevator/orcBase";
import {MeasureCritMem} from "../../hook/useMeasure";
import {SpeedBias} from "./SpeedBias";
import {HandrailBias} from "./HandrailBias";
import {HandrailVibEval, VibrationEval} from "./VibrationEval";
import {Conclusion} from "./Conclusion";
import {SiteConditionSund} from "../../elevator/sundryDj/editor";
import {DeviceSurvey} from "../../park/editor";


export const tItems现场=[
    ['1、机房和机器空间内温度',{f:'T',
        N: <Text>1、机房或者机器设备间的空气温度保持在5℃～40℃之间</Text>},],
    ['2、输入电压波动范围',{f:'V',
        N: <Text>2、电源输入电压波动在额定电压值±7%的范围内</Text>},],
    ['3、湿度不影响运行',{f:'s',
        N: <Text>3、湿度不影响设备正常运行，电器设备无凝露</Text>},],
    ['4、封闭和防护警示',{f:'P',
        N: <Text>4、相关区域没有与电梯运行无关的物品和设备，进行了必要的封闭和防护，放置表明正在进行检测的警示标志</Text>},],
];

//原始记录，一一对应的报告的录入编辑数据，可打印。
const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('Survey', <DeviceSurvey config={config设备概况} label='一、设备概况'/>),
    createItem('Instrument', <ItemInstrumentTable label={'三、主要检测仪器'} prnAttach={'四、 评估原始记录表'}/>),
    createItem('Item', null),
    createItem('Conclusion', <Conclusion/>),
    createItem('ReCheckA', <ItemRecheckEvaluateSplitR label={'表1 不符合安全技术规范要求必须整改的项目'} setup={setupItemAreaRoute} iClass={'A'}/>),
    createItem('ReCheck', <ItemRecheckEvaluateSplitR label={'表2 具有一定潜在安全风险建议整改的项目'} setup={setupItemAreaRoute} />),
    createItem('ReCheckB', <ItemRecheckEvaluateSplitR label={'表3 与现行安全技术规范或标准要求不一致的项目'} setup={setupItemAreaRoute} iClass={'B'}/>),
    createItem('Measure', <MeasureCritMem config={config观测数据} label={'六、观测数据（上）'}>
            </MeasureCritMem>),
    createItem('Measure2', <MeasureCritMem config={config观测数据2} label={'六、观测数据（下）'}>
            </MeasureCritMem>),
    createItem('SpeedBias', <SpeedBias label={`附录A 空载运行速度与名义速度偏差`}/>),
    createItem('HandrailBias', <HandrailBias label={`附录B 扶手带运行速度偏差`}/>),
    createItem('VibrationEval', <VibrationEval label='附录C 运行振动评价表-运载装置'/>),
    createItem('HandrailVibEval', <HandrailVibEval label='附录C 运行振动评价表-扶手带振动'/>),
    createItem('SiteCondition', <SiteConditionSund config={tItems现场} label={'附录D 现场检测条件确认'}/>),
];


export const OriginalView= React.forwardRef((
    { action,  verId, repId='', rep,}:OriginalViewProps, ref
) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const recordPrintListNow =React.useMemo(() => {
        let routeAreas=[] as any[];
        const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
        let extendTags =Reflect.ownKeys(impressionismAs) as string[];
        const oldItCount=recordPrintList.length;
        let prevpos=0;
        for(let p=0; p<oldItCount; p++){
            if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
                routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
                const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
                let seq = 0;
                let moreItems = [] as any;
                itemConfigs.forEach((area, x) => {
                    seq += 1;
                    const rowHead =<ActionMapItemLikeSafeEval key={seq} alone={false} editAreasConf={itemConfigs}
                                                           index={x}   />;
                    moreItems.push(createItem(area.tag, rowHead));
                });
                routeAreas=routeAreas.concat(moreItems);
                prevpos=p+1;
            }
        }
        routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
        return routeAreas;
    }, [verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
        {list}
        {/* <Button  intent="primary"
               onPress={(e) => { handleSubmit!();
               }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
} );
